package www.sharetime.weshare.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import www.sharetime.weshare.R;

/**
 * File Description  : 页面跳转的功能处理工具
 *
 * @author : zhanggeng
 * @email : zhanggengdyx@gmail.com
 * @date : 2017/9/17 13:34
 * @version     : v1.0
 * **************修订历史*************
 */

public class UIUtils {

    public static void startActivity(Context context, Class<?> cls) {
        Intent intent = new Intent();
        intent.setClass(context, cls);
        context.startActivity(intent);
        ((Activity) context).overridePendingTransition(R.anim.push_right_in,
                R.anim.push_left_out);
    }

    public static void startActivity(Context context, Class<?> cls,
                                     Intent intent) {
        if (context instanceof Activity) {
            ((Activity) context).overridePendingTransition(R.anim.push_right_in,
                    R.anim.push_left_out);
            intent.setClass(context, cls);
            context.startActivity(intent);
        }
    }

    public static void startActivity(Context context, Class<?> cls,
                                     Bundle bundle) {

        if (context instanceof Activity) {
            Intent intent = new Intent();
            intent.setClass(context, cls);
            intent.putExtras(bundle);
            context.startActivity(intent);
            ((Activity) context).overridePendingTransition(R.anim.push_right_in,
                    R.anim.push_left_out);
        } else {
            startActivityByApplication(context, cls, bundle);
        }

    }

    public static void startActivityByApplication(Context context, Class<?> cls,
                                                  Bundle bundle) {
        Intent intent = new Intent();
        intent.setClass(context, cls);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    public static void closeActivity(Context context) {
        ((Activity) context).finish();
        ((Activity) context).overridePendingTransition(R.anim.push_left_in,
                R.anim.push_right_out);
    }


    public static void startWebActivity(Context context ,Class<?> cls ,  int index) {
        Bundle bundle = new Bundle();
        bundle.putInt("index", index);
        UIUtils.startActivity(context, cls, bundle);
    }

    public static void startWebActivity(Context context ,Class<?> cls ,  Bundle bundle) {
        UIUtils.startActivity(context, cls, bundle);
    }
}
